package com.hzqy.web.ac.system;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.hzqy.commons.utils.MD5Util;
import com.hzqy.commons.utils.SystemConfigUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.commons.utils.ConstantUtils;
import com.hzqy.service.content.ContentServiceBean;
import com.hzqy.service.system.SysConfigServiceBeen;
import com.hzqy.web.vo.CmContentVo;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.system.SysConfigVo;
@Controller
@RequestMapping("/system")
public class SysConfigAction{
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private SysConfigServiceBeen sysConfigServiceBeen;
	
	@RequestMapping("/add_sys_config")
	@ResponseBody
	public Object sysConfigAdd(SysConfigVo sysConfigVo){
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = sysConfigServiceBeen.insertSystem(sysConfigVo);
		if(flag > 0) {
			resultMap.put("success", true);
			resultMap.put("result","新增内容成功!");
		} else {
			resultMap.put("success", false);
			resultMap.put("result","新增内容失败!flag="+flag);
		}
		return resultMap;
		
	}
	@RequestMapping("/del_sys_config")
	@ResponseBody
	public Object sysConfigDel(int f_sc_id){
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = sysConfigServiceBeen. deleteSystem(f_sc_id);
		resultMap.put("resultTitle", "删除结果");
		if(flag>0) {
			resultMap.put("success", true);
			resultMap.put("result","删除成功!");
		} else {
			resultMap.put("success", false);
			resultMap.put("result","删除失败!");
		}
		return resultMap;
	
	}
	@RequestMapping("/update_sys_config")
	@ResponseBody
	public Object sysConfigUpdate(SysConfigVo sysConfigVo){
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = sysConfigServiceBeen.updateSystem(sysConfigVo);
		if(flag > 0) {
			resultMap.put("success", true);
			resultMap.put("result","修改内容成功!");
		} else {
			resultMap.put("success", false);
			resultMap.put("result","修改内容失败!flag="+flag);
		}
		return resultMap;
		
	}
	@RequestMapping("/sys_config_list")
	@ResponseBody
	public Object sysConfigList(SysConfigVo sysConfigVo, HttpSession session, int page, int rows){
		Map<String,Object> SystemListMap = new HashMap<String, Object>();
		SystemListMap =  sysConfigServiceBeen.selectSysConfigVoList(sysConfigVo,page, rows);
		return SystemListMap;
		
	}
	@RequestMapping("/select_system")
	@ResponseBody
	public Object selectSystem(int f_sc_id) {
		SysConfigVo sysConfigVo = sysConfigServiceBeen.selectSystem(f_sc_id);
		return sysConfigVo;
	}
	@RequestMapping("/select_systemByKey")
	@ResponseBody
	public Object selectSystemByKey(String f_sc_keys) {
		SysConfigVo sysConfigVo = new SysConfigVo();
		HashMap<String, Object> map = new HashMap<>();
		String[] keys = f_sc_keys.split(",");
		for (String f_sc_key: keys) {
			sysConfigVo = sysConfigServiceBeen.selectSystemByKey(f_sc_key);
			map.put(""+sysConfigVo.getF_sc_key(),sysConfigVo.getF_sc_value());
		}
		/*sysConfigVo = sysConfigServiceBeen.selectSystemByKey("wx_manager_password");
		map.put("wx_manager_password",sysConfigVo.getF_sc_value());
		Long systemTime = System.currentTimeMillis();
		map.put("systemTime",systemTime);
		String token = MD5Util.MD5_32bit(SystemConfigUtils.getSysConfig("wx_manager_password")+systemTime);
		map.put("token",token);*/
		return map;
	}

	
	
	
}
